package com.JJL.controller;

import com.JJL.util.SSOUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class LoginController {

    @RequestMapping("/login")
    public String gotoLogin(String username, String password, String gotoUrl, HttpServletRequest request, HttpServletResponse response) throws Exception{
         if(SSOUtil.checkLogin(username,password)){
             Cookie cookie = new Cookie("SameDomSSO","sso");
             cookie.setPath("/");
             //设置七天过期
             cookie.setMaxAge(60*60*24*7);
             response.addCookie(cookie);
             System.out.println(gotoUrl);
             return "redirect:"+gotoUrl;
         }
        return "login";
    }

}
